home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / v_array.zip / VIR.H < prev    next >
Text File  |  1991-09-06  |  3KB  |  70 lines

  1. /**** VIR.H ****/
  2. /**** Virtual array functions header file ****/
  3.  
  4. /**** Error flag test bits ****/
  5.  
  6. #define VFILEerr    0x0001        /* Open/Close error flag bit */
  7. #define VREADerr     0x0002        /* Read error flag bit */
  8. #define VWRITEerr       0x0004        /* Write error flag bit */
  9. #define VSEEKerr    0x0008        /* Seek error flag bit */
  10. #define VLOCKerr    0x0010        /* Lock error flag bit */
  11. #define VUNLOCKerr    0x0020        /* Unlock error flag bit */
  12.  
  13. /**** Option flag test bits ****/
  14.  
  15. #define VDENYRopt    0x0001        /* Deny others read access */
  16. #define VDENYWopt    0x0002        /* Deny others write access */
  17. #define VCREATopt    0x0004        /* Create file if not exist */
  18. #define VTRUNCopt    0x0008        /* Truncate file upon open */
  19. #define VLOCKSopt    0x0010        /* Lock/unlock active pages */
  20. #define VWRITEopt    0x0020        /* Not read only mode */
  21.  
  22. /**** Variable type definitions ****/
  23.  
  24. typedef struct    {int a;int b;} INTS;
  25. typedef union    {long ix;INTS x;} VIX;
  26. typedef struct    {int page;VIX idx;VIX end;} IX;    /* Control structure */
  27.  
  28. /**** Function definitions ****/
  29.  
  30. int V_clr(void *BFR,IX X[]);        /* Virtual clear function */
  31. int V_stop(void *BFR,IX X[]);        /* Virtual close down */
  32. int V_init(char *fname,IX X[]);        /* Virtual initialization */
  33. int V_r(long index,void *BFR,IX X[]);    /* Virtual access operator */
  34.  
  35. /**** Variable macros ****/
  36.  
  37. #define VNext(n)     n##_VX[0].page        /* Buffer age pointer */
  38. #define VFile(n)     n##_VX[0].idx.x.a    /* File handle */
  39. #define VPages(n)     n##_VX[0].idx.x.b    /* # of pages in buffer */
  40. #define VPlen(n)    n##_VX[0].end.x.a    /* Elements per page */
  41. #define VSize(n)    n##_VX[0].end.x.b    /* Bytes per element */
  42. #define VErr(n)        n##_VX[1].page        /* Error flags of last access */
  43. #define VOffset(n)    n##_VX[1].idx.ix    /* Byte offset of array */
  44. #define VOptions(n)    n##_VX[1].end.x.a    /* File access option flags */
  45. #define VPidx(n)    n##_VX[VNext(n)+2].idx.ix  /* Selected page index */
  46. #define VPend(n)       n##_VX[VNext(n)+2].end.ix  /* Selected page end */
  47. #define VREF(n,in)\
  48.     ((in-VPidx(n))+(n##_VX[VNext(n)+2].page*VPlen(n)))
  49.  
  50. /**** Operational macros ****/
  51.  
  52. #define Vdcl(typ,nam,len,pgs)\
  53.     typ nam##_V[len*pgs];\
  54.     IX nam##_VX[pgs+2]=\
  55.     {0,pgs*0x00010000,len+sizeof(typ)*0x00010000}\
  56.  
  57. #define V_(nm,in)\
  58.     nm##_V[((in>=VPidx(nm)&&in<VPend(nm))?(VErr(nm)=0,VREF(nm,in)):\
  59.            (V_r(in,nm##_V,nm##_VX)))]
  60.  
  61. #define Vclr(nam) V_clr(nam##_V,nam##_VX)
  62.  
  63. #define Vstop(nam) V_stop(nam##_V,nam##_VX)
  64.  
  65. #define Vinit(name,fnam,ofs,ops)\
  66.     VOffset(name)=ofs;\
  67.     VOptions(name)=ops;\
  68.     V_init(fnam,name##_VX);
  69.  
  70.